package view;


import java.awt.GridLayout;


import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTextField;

import model.Adressbook;
import controller.AddcontactListener;
import controller.AddcontactmenuListener;
import controller.ListmenuListener;

/**
 * 
 * @author Nelly-Kim TRAN
 * 
 * the view containing the form that allows to add a new contact to the address book
 * the menu allows to add and see the list of contacts
 * All the other parameters are the JLabels and JTextFields of the form
 *
 */

public class AddcontactView extends JFrame{
	
	JPanel panel=new JPanel(new GridLayout(15,2));
	
	//Menu
	JMenuBar menubar=new JMenuBar();
	JMenu menu1=new JMenu("Add Contact");
	JMenuItem item1=new JMenuItem("Add!");
	JMenu menu4=new JMenu("List of Contacts");
	JMenuItem item4=new JMenuItem("See the list!");
	
	//Contact Form
	public JLabel l1=new JLabel("Firstname");
	public JTextField firstname=new JTextField(20);
	public JLabel l2=new JLabel("Lastname");
	public JTextField lastname=new JTextField(20);
	public JLabel l3=new JLabel("Home address");
	public JTextField homeaddress=new JTextField(20);
	public JLabel l4=new JLabel("Company address");
	public JTextField companyaddress=new JTextField(20);
	public JLabel l5=new JLabel("Personal mobile");
	public JTextField personalmobile=new JTextField(20);
	public JLabel l6=new JLabel("Personal home");
	public JTextField personalhome=new JTextField(20);
	public JLabel l7=new JLabel("Professionnal mobile");
	public JTextField professionnalmobile=new JTextField(20);
	public JLabel l8=new JLabel("Professionnal office");
	public JTextField professionnaloffice=new JTextField(20);
	public JLabel l9=new JLabel("Homepage");
	public JTextField homepage=new JTextField(20);
	public JLabel l10=new JLabel("Personnal e-mail");
	public JTextField personnalemail=new JTextField(20);
	public JLabel l11=new JLabel("Professionnal e-mail");
	public JTextField professionnalemail=new JTextField(20);
	public JLabel l12=new JLabel("photo");
	public JTextField photo=new JTextField(20);
	public JLabel l13=new JLabel("group");
	public JTextField group=new JTextField(20);
	public JButton bouton = new JButton("Register!");	

	
	public AddcontactView() {
		super();
		build();
		
		//Listener to add a contact
		AddcontactListener listener1=new AddcontactListener(this);
		bouton.addActionListener(listener1);
		
		
		//Listeners for the menu
		AddcontactmenuListener listener2=new AddcontactmenuListener(this);
		item1.addActionListener(listener2);
		
		ListmenuListener listener3=new ListmenuListener(this);
		item4.addActionListener(listener3);
				
	}
	
	private void build() {
		
		setTitle("My address book"); 
		setSize(600,600);
		
		// Menu
		
		menubar.add(menu1);	
		menu1.add(item1);
		menubar.add(menu4);
		menu4.add(item4);
		setJMenuBar(menubar);
		

		//Panel
		
		panel.add(l1);
		
		panel.add(firstname);
		
		panel.add(l2);
		
		panel.add(lastname);
		
		panel.add(l3);
		
		panel.add(homeaddress);
		
		panel.add(l4);
		
		panel.add(companyaddress);
		
		panel.add(l5);
		
		panel.add(personalmobile);
		
		panel.add(l6);
		
		panel.add(personalhome);
		
		panel.add(l7);
		
		panel.add(professionnalmobile);
		
		panel.add(l8);
		
		panel.add(professionnaloffice);
		
		panel.add(l9);
		
		panel.add(homepage);
		
		panel.add(l10);
		
		panel.add(personnalemail);
		
		panel.add(l11);
		
		panel.add(professionnalemail);
		
		panel.add(l12);
		
		panel.add(photo);
		
		panel.add(l13);
		
		panel.add(group);
		
		panel.add(bouton);

		setContentPane(panel);
	}
	

	
	

}
